package org.atf.model.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.atf.model.entity.LdapConfig;
import org.atf.model.entity.User;
import org.atf.model.utils.EntityManagerUtil;

public class LdapConfigDAO {
	
	public List<LdapConfig> getAllLdapConfig(){	
		EntityManager entityManager=EntityManagerUtil.getEntityManager();
		Query query = entityManager.createQuery("select u from LdapConfig u ");	
		List<LdapConfig> resultList = query.getResultList();
		return resultList;
	}
	
	public void updateLdapConfig(LdapConfig ldapConfig){
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
		try{
			entityManager.getTransaction().begin();
			entityManager.merge(ldapConfig);
			entityManager.getTransaction().commit();
		}finally {
			//entityManager.close();
		}
		
	}
	public void insertLdapConfig(LdapConfig ldapConfig){
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
		try{
			entityManager.getTransaction().begin();
			entityManager.persist(ldapConfig);
			entityManager.getTransaction().commit();
		}finally {
			//entityManager.close();
		}
	}
}
